/**
 * 
 * @authors Riche
 * @date    2016-11-20 16:39:39
 * @version 1.0.1
 */
var myLoad = {
	//页面载入时加载
	init : function(){
		var str = "";
		str+="<div class=\"loading-popbg loadBox\">";
		str+="</div>";
		str+="<div class=\"loading-page loadBox\">";
		str+="   <img src=\"images/loading.gif\" class=\"loading-img\">";
		str+="   <span class=\"loading-text\">正在加载中...</span>";
		str+="</div>";
		document.write(str);
		//document.body.appendChild(loadBox);
		//$ ('body *:first').before(htmldata);
		var html = document.getElementsByTagName('html')[0];
		html.style.height = "100%";
		html.style.overflow = "hidden";
		document.body.style.height = "100%";
		document.body.style.overflow = "hidden";
	},
	//页面加载完成
	loaded:function() { 
	    //适当延迟隐藏，提高loading效果
	    setTimeout(function() {
	    	var loadBoxList = document.getElementsByClassName('loadBox');
	    	for(var i=0;i<loadBoxList.length;i++){
	    		loadBoxList[i].style.display = 'none';
	    	}
	    
		    var html = document.getElementsByTagName('html')[0]
			html.style.height = "";
			html.style.overflow = "";
			document.body.style.height = "";
			document.body.style.overflow = "";
	    //$('.loadBox').delay(1000).remove(); 
	    //$('html,body').css({'height':'','overflow':''});
	    }, 1000);
	},
	/*  下拉加载
	**  @param {string} parentContainer 父容器 
	**  @param {string} content 添加的内容
	**
	**  eg. var str = '<img class="loading" src="images/loading.gif"></img>';
	**     	myLoad.pullLoad('quesCont',str);
	*/
	pullLoad:function(parentContainer,content){
		//判断该元素是否存在
		var loadingLength = document.getElementsByClassName('loading-more').length;
		if(loadingLength>0){
			for(var i=0;i<loadingLength;i++){
				document.getElementsByClassName('loading-more')[i].innerHTML = content;
			}
		}else{  //不存在创建新的
			var span = document.createElement('span');
			span.setAttribute('class','loading-more');
			;
			content ? (span.innerHTML = content) : (span.innerHTML = '加载更多...');
			document.getElementsByClassName(parentContainer)[0] && (document.getElementsByClassName(parentContainer)[0].appendChild(span));
		}
	},
	pullHide:function(){
		//判断该元素是否存在
		var loadingLength = document.getElementsByClassName('loading-more').length;
		if(loadingLength>0){
			for(var i=0;i<loadingLength;i++){
				document.getElementsByClassName('loading-more')[i].innerHTML = '加载更多...';
			}
		}
		//document.getElementsByClassName('loading-more')[0] && (document.getElementsByClassName('loading-more')[0].innerHTML = '加载更多...');
	},
	pullHidden:function(){
		var loadingLength = document.getElementsByClassName('loading-more').length;
		if(loadingLength>0){
			for(var i=0;i<loadingLength;i++){
				document.getElementsByClassName('loading-more')[i].style.visibility = 'hidden';
			}
		}
		//document.getElementsByClassName('loading-more')[0] && (document.getElementsByClassName('loading-more')[0].style.visibility = 'hidden');
	},
	noDate:function(str){
		str ? str : str = '暂无数据';
		var loadingLength = document.getElementsByClassName('loading-more').length;
		if(loadingLength>0){
			for(var i=0;i<loadingLength;i++){
				document.getElementsByClassName('loading-more')[i].innerHTML = str;
			}
		}
		//document.getElementsByClassName('loading-more')[0] && (document.getElementsByClassName('loading-more')[0].innerHTML = '暂无数据');
		
		
	}
}

myLoad.init();

window.onload = function(){
	myLoad.loaded();
}